package com.pot.admin.config.security;

import com.pot.common.enums.DeleteFlagEnum;
import com.pot.common.enums.DisableFlagEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;

@Data
public class UserInfoData implements UserDetails {

    /**
     *
     */
    private Integer id;

    /**
     *用户头像
     */
    private String avatar;
    /**
     *用户昵称
     */
    private String nickname;

    /**
     *用户账号
     */
    private String username;

    /**
     *用户密码
     */
    private String password;

    /**
     *是否禁用: [0=否, 1=是]
     */
    private Integer isDisable;

    /**
     *是否删除: [0=否, 1=是]
     */
    private Integer isDelete;

    /**
     *
     */
    private List<GrantedAuthority> authorities;



    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public String getPassword() {
        return password;
    }

    @Override
    public String getUsername() {
        return username;
    }

    @Override
    public boolean isAccountNonExpired() {
        return isDelete.equals(DeleteFlagEnum.UN_DELETE.getCode());
    }

    @Override
    public boolean isAccountNonLocked() {
        return isDisable.equals(DisableFlagEnum.ENABLE.getCode());
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return isDelete.equals(DeleteFlagEnum.UN_DELETE.getCode());
    }
}
